home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / BUSINESS / SALE24.ARJ / PRINEX4.PRG < prev    next >
Text File  |  1992-04-21  |  2KB  |  94 lines

  1. // Prinex4.prg
  2.  
  3. #include "Setcurs.ch"
  4.  
  5. #define BAR_LIMIT         1     // Limit on # of elems in scroll bar
  6. #define BAR_CURRENT       2     // Number of positions marked so far
  7. #define BAR_SAVE_SCREEN   3     // Screen area overwritten
  8. #define BAR_SAVE_CURSOR   4     // Old cursor shape
  9. #define BAR_ELEMS_POS     5     // Elements per position
  10. #define BAR_CUR_NUM_ELEMS 6     // Number of positions displayed
  11.                                 // so far
  12.  
  13. #define BAR_TOP    20
  14. #define BAR_LEFT   10
  15. #define BAR_BOTTOM 22
  16. #define BAR_RIGHT  70
  17. #define BAR_NUM_ELEMS  ((BAR_RIGHT - 1) - (BAR_LEFT + 1) + 1)
  18.  
  19.  
  20. FUNCTION Test
  21.  
  22. LOCAL aBar
  23. FIELD Lname IN Tbdbf1
  24.  
  25.   CLEAR SCREEN
  26.  
  27.   // Sample call
  28.   USE TbDbf1
  29.  
  30.   aBar := BarNew(RecCount())
  31.  
  32.   // Note - to avoid calling the function so frequently, include
  33.   // a test such as iif(recno() % 10 = 0, BarMark(...), "")
  34.   // as the second expression inside the block
  35.   dbCreateIndex( "x", "Upper(Lname)", ;
  36.                 {|| Upper(Lname) + BarMark(aBar, Recno())})
  37.   BarEnd(aBar)
  38.  
  39. RETURN NIL
  40.  
  41.  
  42. // Call before start to get a bar "object"
  43. FUNCTION BarNew(nRecs)
  44.  
  45. LOCAL aBar := {nRecs, 0, ;
  46.                SaveScreen(BAR_TOP, BAR_LEFT, BAR_BOTTOM, BAR_RIGHT), ;
  47.                SetCursor(SC_NONE), NIL, NIL}
  48.  
  49.   aBar[BAR_ELEMS_POS] := Int(nRecs / BAR_NUM_ELEMS)
  50.   IF aBar[BAR_ELEMS_POS] < (nRecs / BAR_NUM_ELEMS)
  51.     aBar[BAR_ELEMS_POS]++
  52.   ENDIF
  53.  
  54.   aBar[BAR_CUR_NUM_ELEMS]  := 0
  55.  
  56.   @ BAR_TOP, BAR_LEFT CLEAR TO BAR_BOTTOM, BAR_RIGHT
  57.   @ BAR_TOP, BAR_LEFT       TO BAR_BOTTOM, BAR_RIGHT
  58.  
  59. RETURN aBar
  60.  
  61.  
  62. // Call to mark a new position in the bar "object"
  63. FUNCTION BarMark(aBar, nRecno)
  64.  
  65. LOCAL nPos := Int(nRecNo / aBar[BAR_ELEMS_POS])
  66. LOCAL nDisp := nPos - aBar[BAR_CUR_NUM_ELEMS]
  67.  
  68.   
  69.   IF !Eof()
  70.     @ BAR_TOP + 1, BAR_LEFT + 1 + aBar[BAR_CUR_NUM_ELEMS] ;
  71.       SAY Replicate(Chr(254), nDisp)
  72.  
  73.    aBar[BAR_CUR_NUM_ELEMS] := nPos
  74.   ENDIF
  75.  
  76. RETURN ""
  77.  
  78.  
  79. // Call after finished to complete the bar "object" and
  80. // restore the screen
  81.  
  82. FUNCTION BarEnd(aBar)
  83.  
  84.   @ BAR_TOP + 1, BAR_LEFT + 1 SAY Replicate(Chr(254), ;
  85.                                             BAR_NUM_ELEMS)
  86.   // Let them see the entire bar for an instant ...
  87.   InKey(.1)
  88.   RestScreen(BAR_TOP, BAR_LEFT, ;
  89.              BAR_BOTTOM, BAR_RIGHT, ;
  90.              aBar[BAR_SAVE_SCREEN])
  91.   SetCursor(aBar[BAR_SAVE_CURSOR])
  92.  
  93. RETURN NIL
  94.